#include "StdAfx.h"
#include "ScrambledEggsFactory.h"
#include "StdAfx.h"
#include "graphics/OpenGLWnd.h"
#include "graphics/GrVector.h"
#include "SgObject.h"
#include "RoundUpFactory.h"
#include "SgColor.h"
#include "SgBox.h"
#include "SgQuad.h"
#include "SgComposite.h"
#include "SgMaterial.h"
#include "SgPolygon.h"
#include "SgRegularPolygon.h"
#include "SgRegularCylinder.h"
#include "SgRotateAroundPoint.h"
#include "SgTranslate.h"
#include "SgTransform.h"
#include "AnimationRotateScrambledEggs.h"
#include "SgMesh.h"
#include <math.h>
#include <vector>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

inline void Normalize(GLdouble *v)
{
    GLdouble len = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
    v[0] /= len;
    v[1] /= len;
    v[2] /= len;
}

CScrambledEggsFactory::CScrambledEggsFactory(void)
{
	m_root = NULL;
	m_FrontRadius = .6;
	m_StairWidth = 1.0;
	m_StairDepth = 1.0;
	m_FrontSides = 180;
	m_SeatHeight = 2.3;
	m_SeatWidth = 4;
	m_SeatDepth = 1.4;
	m_SeatSides = 120;
	m_FrontWidth = m_SeatWidth*.7;
	rainbowTex = new CSgTexture(L"rainbow.bmp");
	backOfChair = new CSgTexture(L"test2.bmp");
	roundedFrontTex = new CSgTexture(L"eggs.bmp");
	steelTex = new CSgTexture(L"stainlesssteel.bmp");
	lastTex = new CSgTexture(L"fun.bmp");
}

CScrambledEggsFactory::~CScrambledEggsFactory(void)
{
}

void CScrambledEggsFactory::Create(CSgComposite *root)
{
	m_root = root;

	CSgPtr<CSgTranslate> move = new CSgTranslate();
	move->SetProperties(-35.0,m_SeatDepth*1.5,-30.0);

	CSgPtr<CSgRotateAroundPoint> spin = new CSgRotateAroundPoint();
	spin->SetNormal(0, 1, 0);
	spin->SetPoint(0, 0, 0);
	spin->SetAngle(0);


	CSgPtr<CAnimationRotateScrambledEggs> animateSpin =
		new CAnimationRotateScrambledEggs();
	animateSpin->SetNode(spin);

	m_timeline->AddChannel(animateSpin);

	CSgPtr<CSgMaterial> rideMaterial = new CSgMaterial();
	rideMaterial->SetDiffuseColor(0.9f, 0.9f, 0.9f, 1.f);
	rideMaterial->SetSpecularColor(0.9f, 0.9f, 0.9f, 1.f);
	rideMaterial->SetShininess(30.0);
	PutTogether(rideMaterial);
	spin->AddChild(rideMaterial);

	move->AddChild(spin);
	m_root->AddChild(move);
}

void CScrambledEggsFactory::PutTogether(CSgComposite *parent)
{
	//
	CreateRideCenter(parent);
	for(int i = 0; i < 3; i++)
	{
		CSgPtr<CSgRotateAroundPoint> spin = new CSgRotateAroundPoint();
		spin->SetNormal(0, 1, 0);
		spin->SetPoint(0, 0, 0);
		spin->SetAngle(0);


		CSgPtr<CAnimationRotateScrambledEggs> animateSpin =
			new CAnimationRotateScrambledEggs();
		animateSpin->SetNode(spin);

		m_timeline->AddChannel(animateSpin);

		CreateFinalArm(spin);

		CSgPtr<CSgTranslate> moveArm = new CSgTranslate();
		moveArm->SetProperties(0.0,0.0,m_StairDepth*15);
		moveArm->AddChild(spin);
		CSgPtr<CSgRotateAroundPoint> positionArm = new CSgRotateAroundPoint();
		positionArm->SetPoint(CGrVector(0.0,0.0,0.0));
		positionArm->SetAngle(120*i);
		positionArm->SetNormal(CGrVector(0.0,1.0,0.0));
		positionArm->AddChild(moveArm);

		CSgPtr<CSgTranslate> moveBeamBottom = new CSgTranslate();
		moveBeamBottom->SetProperties(-.1999,-1*m_SeatDepth,0.0);
		CreateLongConnect(moveBeamBottom);
		positionArm->AddChild(moveBeamBottom);

		CSgPtr<CSgTranslate> moveBeamTop = new CSgTranslate();
		moveBeamTop->SetProperties(-.2,m_SeatDepth*4-.401,0.0);
		CreateLongConnect(moveBeamTop);

		positionArm->AddChild(moveBeamTop);

		parent->AddChild(positionArm);
	}
}

void CScrambledEggsFactory::CreateLongConnect(CSgComposite *parent)
{
	//a-b
	//|\ \  d
	//c e-f
	// \| |
	//	g-h
	CSgPtr<CSgMesh> connector = new CSgMesh();
	GLdouble length = m_SeatDepth*11-.3;
	GLdouble width = .4;
	GLdouble height = .4;

	GLdouble a[] = {0.0,height,0.0};
	GLdouble b[] = {width,height, 0.0};
	GLdouble c[] = {0.0,0.0,0.0};
	GLdouble d[] = {width,0.0,0.0};
	GLdouble e[] = {0.0,height,length};
	GLdouble f[] = {width, height, length};
	GLdouble g[] = {0.0,0.0,length};
	GLdouble h[] = {width,0.0,length};

	connector->AddVertex(a);//0
	connector->AddVertex(b);//1
	connector->AddVertex(c);//2
	connector->AddVertex(d);//3
	connector->AddVertex(e);//4
	connector->AddVertex(f);//5
	connector->AddVertex(g);//6
	connector->AddVertex(h);//7

	connector->AddNormal(CGrVector(0.0,0.0,1.0));
	connector->AddNormal(CGrVector(0.0,0.0,-1.0));
	connector->AddNormal(CGrVector(0.0,1.0,0.0));
	connector->AddNormal(CGrVector(0.0,-1.0,0.0));
	connector->AddNormal(CGrVector(1.0,0.0,0.0));
	connector->AddNormal(CGrVector(-1.0,0.0,0.0));
	//a-b
	//|\ \  d
	//c e-f
	// \| |
	//	g-h
	connector->AddFlatQuad(3,2,1,0,1);
	connector->AddFlatQuad(5,4,6,7,0);
	connector->AddFlatQuad(1,0,4,5,2);
	connector->AddFlatQuad(1,5,7,3,4);
	connector->AddFlatQuad(7,6,2,3,3);
	connector->AddFlatQuad(4,0,2,6,5);
	parent->AddChild(connector);
}

void CScrambledEggsFactory::CreateRideCenter(CSgComposite *parent)
{
	CSgPtr<CSgRegularCylinder> center = new CSgRegularCylinder();
	center->SetProperties(120,m_SeatDepth*4,0.4);
	
	steelTex->AddChild(center);
	parent->AddChild(steelTex);
	

	CSgPtr<CSgRegularCylinder> bottom = new CSgRegularCylinder();
	bottom->SetProperties(360,m_SeatDepth*1.5,2);
	CSgPtr<CSgTranslate> moveBottom = new CSgTranslate();
	moveBottom->SetProperties(0.0,-1.5*m_SeatDepth,0.0);
	moveBottom->AddChild(bottom);
	lastTex->AddChild(moveBottom);
	parent->AddChild(lastTex);

	//b   c
	//
	//d   e 
	//  
	//  a

	/*GLdouble a[] = {0.0,0.0,0.0};
	GLdouble b[] = {-.5,.5,-.5};
	GLdouble c[] = {.5,.5,-.5};
	GLdouble d[] = {-.5,.5,.5};
	GLdouble e[] = {.5,.5,.5};

	CSgPtr<CSgMesh> topPyramid = new CSgMesh();
	topPyramid->AddVertex(a);//1
	topPyramid->AddVertex(b);//2
	topPyramid->AddVertex(c);//3
	topPyramid->AddVertex(d);//4
	topPyramid->AddVertex(e);//5
	topPyramid->AddVertex(f);//6
	topPyramid->AddNormal(CGrVector(0.0,-.5

	topPyramid->AddFlatTriangle(1,5,4,0);
	topPyramid->AddNormal(CGrVector(0.0,sin(225*(M_PI/180)),cose(225*(M_PI/180))*/

}

void CScrambledEggsFactory::CreateFinalArm(CSgComposite *parent)
{

	CSgPtr<CSgMaterial> yellow = new CSgMaterial();
	yellow->SetDiffuseColor(1.0f, 1.0f, 0.0f, 1.f);
	yellow->SetSpecularColor(1.0f, 1.0f, 0.0f, 1.f);
	yellow->SetShininess(20.0);

	CSgPtr<CSgMaterial> pink = new CSgMaterial();
	pink->SetDiffuseColor((233.0f/255.0f), 22.0f/255.0f, 217.0f/255.0f, 1.0f);
	pink->SetSpecularColor((233.0f/255.0f), 22.0f/255.0f, 217.0f/255.0f, 1.0f);
	pink->SetShininess(20.0);

	CSgPtr<CSgMaterial> blue = new CSgMaterial();
	blue->SetDiffuseColor((38.0f/255.0f), 128.0f/255.0f, 217.0f/255.0f, 1.0f);
	blue->SetSpecularColor((38.0f/255.0f), 128.0f/255.0f, 217.0f/255.0f, 1.0f);
	blue->SetShininess(20.0);

	CSgPtr<CSgMaterial> green = new CSgMaterial();
	green->SetDiffuseColor((27.0f/255.0f), 228.0f/255.0f, 50.0f/255.0f, 0.2f);
	green->SetSpecularColor((27.0f/255.0f), 228.0f/255.0f, 50.0f/255.0f, 1.0f);
	green->SetShininess(20.0);

	std::vector< CSgMaterial *> chairMaterials;
	chairMaterials.push_back(yellow);
	chairMaterials.push_back(pink);
	chairMaterials.push_back(blue);
	chairMaterials.push_back(green);

	CSgPtr<CSgMaterial> rideMaterial = new CSgMaterial();
	rideMaterial->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.f);
	rideMaterial->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.f);
	rideMaterial->SetShininess(20.0);
	
	CreateArmCenter(rideMaterial);
	parent->AddChild(rideMaterial);

	for(int i = 0; i < 4; i++)
	{
		PutTogetherArm(chairMaterials[i]);

		CSgPtr<CSgRotateAroundPoint> positionArm = new CSgRotateAroundPoint();
		positionArm->SetPoint(CGrVector(0.0,0.0,0.0));
		positionArm->SetAngle(90*i);
		positionArm->SetNormal(CGrVector(0.0,1.0,0.0));
		positionArm->AddChild(chairMaterials[i]);

		parent->AddChild(positionArm);
	}
}

void CScrambledEggsFactory::CreateArmCenter(CSgComposite *parent)
{
	CSgPtr<CSgRegularCylinder> center = new CSgRegularCylinder();
	center->SetProperties(45,m_SeatDepth*4,0.3);
	rainbowTex->AddChild(center);

	CSgPtr<CSgRegularCylinder> bottom = new CSgRegularCylinder();
	bottom->SetProperties(8,1,2);
	CSgPtr<CSgTranslate> moveBottom = new CSgTranslate();
	moveBottom->SetProperties(0.0,-1.0,0.0);
	moveBottom->AddChild(bottom);

	CSgPtr<CSgRegularCylinder> top = new CSgRegularCylinder();
	top->SetProperties(4,.5,m_SeatDepth);
	CSgPtr<CSgTranslate> moveTop = new CSgTranslate();
	moveTop->SetProperties(0.0,m_SeatDepth*3+.2,0.0);
	moveTop->AddChild(top);

	parent->AddChild(moveTop);
	parent->AddChild(moveBottom);
	parent->AddChild(rainbowTex);
}


void CScrambledEggsFactory::PutTogetherArm(CSgComposite *parent)
{
	CSgPtr<CSgRotateAroundPoint> positionArm = new CSgRotateAroundPoint();
	positionArm->SetPoint(CGrVector(0.0,0.0,0.0));
	positionArm->SetAngle(90);
	positionArm->SetNormal(CGrVector(-1.0,0.0,0.0));
	CreateArm(positionArm);
	CreateSupport(positionArm);
	CSgPtr<CSgTranslate> moveArm = new CSgTranslate();
	moveArm->SetProperties(0.0,-1*(m_SeatDepth/2.0),m_SeatDepth*7+5.0*(1.0/12.0));
	moveArm->AddChild(positionArm);

	parent->AddChild(moveArm);

	CSgPtr<CSgTranslate> moveChairToRotate = new CSgTranslate();
	moveChairToRotate->SetProperties(-1*((1.0/pow(m_SeatHeight,(1.0/9.0)))+m_SeatWidth/2),-1*(m_SeatDepth/2.0),-1*(m_SeatDepth/2.0));
	CreateCart(moveChairToRotate);
	CSgPtr<CSgRotateAroundPoint> positionChair = new CSgRotateAroundPoint();
	positionChair->SetPoint(CGrVector(0.0,0.0,0.0));
	positionChair->SetAngle(90);
	positionChair->SetNormal(CGrVector(0.0,1.0,0.0));
	positionChair->AddChild(moveChairToRotate);
	CSgPtr<CSgTranslate> moveChairFinal = new CSgTranslate();
	moveChairFinal->SetProperties(0.0,0.0,m_SeatDepth*5+m_SeatWidth/2.0);
	moveChairFinal->AddChild(positionChair);

	parent->AddChild(moveChairFinal);

	CSgPtr<CSgRegularCylinder> seatToBase = new CSgRegularCylinder();
	seatToBase->SetProperties(45, 4*m_SeatDepth,(1.0/12.0));
	CSgPtr<CSgRotateAroundPoint> positionPole = new CSgRotateAroundPoint();
	positionPole->SetPoint(CGrVector(0.0,0.0,0.0));
	positionPole->SetAngle(80);
	positionPole->SetNormal(CGrVector(-1.0,0.0,0.0));
	positionPole->AddChild(seatToBase);
	CSgPtr<CSgTranslate> moveSupportPole = new CSgTranslate();
	moveSupportPole->SetProperties(0.0,-.2,-1.8);
	moveSupportPole->AddChild(positionPole);

	parent->AddChild(moveSupportPole);
}

void CScrambledEggsFactory::CreateArm(CSgComposite *parent)
{
	for (int i = 0; i < 6; i++)
	{
		CSgPtr<CSgTranslate> moveBeamPiece = new CSgTranslate();
		moveBeamPiece->SetProperties(-1*(m_SeatDepth/2),m_SeatDepth*i,0.0);
		CreateBeamPiece(moveBeamPiece);
		parent->AddChild(moveBeamPiece);
	}
	
}
void CScrambledEggsFactory::CreateSupport(CSgComposite *parent)
{
	CSgPtr<CSgRegularCylinder> left = new CSgRegularCylinder();
	CSgPtr<CSgRegularCylinder> right = new CSgRegularCylinder();
	CSgPtr<CSgRegularCylinder> mid = new CSgRegularCylinder();

	double topLength = sqrt(pow((m_SeatDepth*3)*2,2));

	left->SetProperties(45,topLength,(1.0/12.0));
	CSgPtr<CSgRotateAroundPoint> positionLeft = new CSgRotateAroundPoint();
	positionLeft->SetPoint(CGrVector(0.0,0.0,0.0));
	positionLeft->SetAngle(40);
	positionLeft->SetNormal(CGrVector(1.0,0.0,0.0));
	positionLeft->AddChild(left);
	CSgPtr<CSgTranslate> moveLeft = new CSgTranslate();
	moveLeft->SetProperties(-1*(m_SeatDepth/2.0),(1.0/12.0)+m_SeatDepth*2,0.0);
	moveLeft->AddChild(positionLeft);

	right->SetProperties(45,topLength,(1.0/12.0));
	CSgPtr<CSgRotateAroundPoint> positionRight = new CSgRotateAroundPoint();
	positionRight->SetPoint(CGrVector(0.0,0.0,0.0));
	positionRight->SetAngle(40);
	positionRight->SetNormal(CGrVector(1.0,0.0,0.0));
	positionRight->AddChild(right);
	CSgPtr<CSgTranslate> moveRight = new CSgTranslate();
	moveRight->SetProperties(m_SeatDepth/2.0,(1.0/12.0)+m_SeatDepth*2,0.0);
	moveRight->AddChild(positionRight);

	parent->AddChild(moveLeft);
	parent->AddChild(moveRight);
}

void CScrambledEggsFactory::CreateBeamPiece(CSgComposite *parent)
{
	CSgPtr<CSgRegularCylinder> left = new CSgRegularCylinder();
	CSgPtr<CSgRegularCylinder> right = new CSgRegularCylinder();
	CSgPtr<CSgRegularCylinder> across = new CSgRegularCylinder();
	CSgPtr<CSgRegularCylinder> diagonal = new CSgRegularCylinder();

	left->SetProperties(45,m_SeatDepth,(1.0/12.0));

	CSgPtr<CSgTranslate> moveRight = new CSgTranslate();
	moveRight->SetProperties(m_SeatDepth,0.0,0.0);
	right->SetProperties(45,m_SeatDepth,(1.0/12.0));
	moveRight->AddChild(right);

	CSgPtr<CSgRotateAroundPoint> positionBottom = new CSgRotateAroundPoint();
	positionBottom->SetPoint(CGrVector(0.0,0.0,0.0));
	positionBottom->SetAngle(90);
	positionBottom->SetNormal(CGrVector(0.0,0.0,-1.0));
	across->SetProperties(45,m_SeatDepth,(1.0/12.0));
	positionBottom->AddChild(across);
	CSgPtr<CSgTranslate> moveBottom = new CSgTranslate();
	moveBottom->SetProperties(0.0,(1.0/12.0),0.0);
	moveBottom->AddChild(positionBottom);

	//This needs to intersect or it won't look right
	double diagonalLength = sqrt(2*pow(m_SeatDepth,2));
	diagonal->SetProperties(45,diagonalLength,(1.0/12.0));
	CSgPtr<CSgRotateAroundPoint> positionDiagonal = new CSgRotateAroundPoint();
	positionDiagonal->SetPoint(CGrVector(0.0,0.0,0.0));
	positionDiagonal->SetAngle(45);
	positionDiagonal->SetNormal(CGrVector(0.0,0.0,1.0));
	positionDiagonal->AddChild(diagonal);
	CSgPtr<CSgTranslate> moveDiagonal = new CSgTranslate();
	moveDiagonal->SetProperties(m_SeatDepth,(1.0/12.0),0.0);
	moveDiagonal->AddChild(positionDiagonal);

	parent->AddChild(left);
	parent->AddChild(moveRight);
	parent->AddChild(moveBottom);
	parent->AddChild(moveDiagonal);

}
void CScrambledEggsFactory::CreateCart(CSgComposite *parent)
{
	//stairs and rounted front
	CSgPtr<CSgRotateAroundPoint> positionFrontAndStairs = new CSgRotateAroundPoint();
	positionFrontAndStairs->SetPoint(CGrVector(0.0,0.0,0.0));
	positionFrontAndStairs->SetAngle(90);
	positionFrontAndStairs->SetNormal(CGrVector(0.0,0.0,1.0));
	CreateCartFront(positionFrontAndStairs);

	CSgPtr<CSgTranslate> moveStairs = new CSgTranslate();
	moveStairs->SetProperties(0.0,-1*2*m_FrontRadius+.001,0.0);
	CreateCartStair(moveStairs);
	positionFrontAndStairs->AddChild(moveStairs);

	CSgPtr<CSgTranslate> moveFront = new CSgTranslate();
	moveFront->SetProperties(m_FrontWidth+(1.0/pow(m_SeatHeight,(1.0/9.0)))+((m_SeatWidth*.3)/2),m_FrontRadius,m_SeatDepth+m_StairWidth);
	moveFront->AddChild(positionFrontAndStairs);
	
	//cart feet
	CSgPtr<CSgTranslate> moveFeet = new CSgTranslate();
	moveFeet->SetProperties(0.0,0.0,0.0001);
	CreateCartFeet(moveFeet);
	
	
	//cart latch
	CSgPtr<CSgRotateAroundPoint> positionLatch = new CSgRotateAroundPoint();
	positionLatch->SetPoint(CGrVector(0.0,0.0,0.0));
	positionLatch->SetAngle(90);
	positionLatch->SetNormal(CGrVector(0.0,0.0,-1.0));
	CreateCartLatch(positionLatch);
	CSgPtr<CSgTranslate> moveLatch = new CSgTranslate();
	moveLatch->SetProperties((1.0/pow(m_SeatHeight,(1.0/9.0))),m_SeatHeight-.2,m_SeatDepth);
	moveLatch->AddChild(positionLatch);

	parent->AddChild(moveFront);//front
	CreateSeatContainer(parent);//seat
	parent->AddChild(moveFeet); // feet
	parent->AddChild(moveLatch);
}

void CScrambledEggsFactory::CreateCartLatch(CSgComposite *parent)
{
	CSgPtr<CSgRegularCylinder> topCylindar = new CSgRegularCylinder();
	topCylindar->SetProperties(180,m_SeatWidth, 1.0/15.0);

	CSgPtr<CSgRegularCylinder> bottomCylindar = new CSgRegularCylinder();
	bottomCylindar->SetProperties(180,m_SeatWidth, 1.0/15.0);
	CSgPtr<CSgTranslate> moveBottom = new CSgTranslate();
	moveBottom->SetProperties(8.0/12.0,0.0,0.0);
	moveBottom->AddChild(bottomCylindar);

	//a b
	//
	//c d

	// e f
	//
	// g h

	CSgPtr<CSgMesh> panel = new CSgMesh();

	GLdouble a[] = {0.0,m_SeatWidth,-1*(1.0/23.0)};
	GLdouble b[] = {8.0/12.0, m_SeatWidth, -1*(1.0/23.0)};
	GLdouble c[] = {0.0,0.0,-1*(1.0/23.0)};
	GLdouble d[] = {8.0/12.0,0.0,-1*(1.0/23.0)};
	GLdouble e[] = {0.0,m_SeatWidth,1.0/23.0};
	GLdouble f[] = {8.0/12.0, m_SeatWidth, 1.0/23.0};
	GLdouble g[] = {0.0,0.0,1.0/23.0};
	GLdouble h[] = {8.0/12.0,0.0,1.0/23.0};

	panel->AddVertex(a);//0
	panel->AddVertex(b);//1
	panel->AddVertex(c);//2
	panel->AddVertex(d);//3
	panel->AddVertex(e);//4
	panel->AddVertex(f);//5
	panel->AddVertex(g);//6
	panel->AddVertex(h);//7

	panel->AddNormal(CGrVector(0.0,0.0,1.0));
	panel->AddNormal(CGrVector(0.0,1.0,0.0));
	panel->AddNormal(CGrVector(0.0,0.0,-1.0));
	panel->AddNormal(CGrVector(0.0,-1.0,0.0));

	panel->AddFlatQuad(0,1,3,2,2);
	panel->AddFlatQuad(5,4,6,7,0);
	panel->AddFlatQuad(4,0,2,6,0);
	panel->AddFlatQuad(1,5,7,3,0);
	panel->AddFlatQuad(7,6,2,3,3);
	panel->AddFlatQuad(1,0,4,5,1);

	parent->AddChild(panel);
	parent->AddChild(moveBottom);
	parent->AddChild(topCylindar);
}

void CScrambledEggsFactory::CreateCartFeet(CSgComposite *parent)
{
	CSgPtr<CSgQuad> feetBottom = new CSgQuad();
	CSgPtr<CSgQuad> feetLeftSide = new CSgQuad();
	CSgPtr<CSgQuad> feetRightSide = new CSgQuad();
	CSgPtr<CSgQuad> feetBack = new CSgQuad();

	/*
	   a b
	 e     g
	 f c d h
	*/
	GLdouble a[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+((m_SeatWidth*.3)/2),m_FrontRadius,m_SeatDepth};
	GLdouble b[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+m_FrontWidth+((m_SeatWidth*.3)/2),m_FrontRadius,m_SeatDepth};
	GLdouble c[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+((m_SeatWidth*.3)/2),0.0,m_SeatDepth};
	GLdouble d[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+m_FrontWidth+((m_SeatWidth*.3)/2),0.0,m_SeatDepth};
	GLdouble e[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+((m_SeatWidth*.3)/2),m_FrontRadius,m_SeatDepth+m_StairWidth};
	GLdouble f[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+((m_SeatWidth*.3)/2),0.0,m_SeatDepth+m_StairWidth};
	GLdouble g[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+m_FrontWidth+((m_SeatWidth*.3)/2),m_FrontRadius,m_SeatDepth+m_StairWidth};
	GLdouble h[] = {(1.0/pow(m_SeatHeight,(1.0/9.0)))+m_FrontWidth+((m_SeatWidth*.3)/2),0.0,m_SeatDepth+m_StairWidth};

	feetBottom->SetProperties(d,c,f,h);
	feetLeftSide->SetProperties(a,e,f,c);
	feetRightSide->SetProperties(g,b,d,h);
	feetBack->SetProperties(b,a,c,d);

	CSgPtr<CSgQuad> feetBottomRev = new CSgQuad();
	CSgPtr<CSgQuad> feetLeftSideRev = new CSgQuad();
	CSgPtr<CSgQuad> feetRightSideRev = new CSgQuad();
	CSgPtr<CSgQuad> feetBackRev = new CSgQuad();

	feetBottomRev->SetProperties(h,f,c,d);
	feetLeftSideRev->SetProperties(c,f,e,a);
	feetRightSideRev->SetProperties(h,d,b,g);
	feetBackRev->SetProperties(d,c,a,b);

	parent->AddChild(feetBottom);
	parent->AddChild(feetLeftSide);
	parent->AddChild(feetRightSide);
	parent->AddChild(feetBack);
	parent->AddChild(feetBottomRev);
	parent->AddChild(feetLeftSideRev);
	parent->AddChild(feetRightSideRev);
	parent->AddChild(feetBackRev);
}

void CScrambledEggsFactory::CreateSeatContainer(CSgComposite *parent)
{
	//unique translate for each one
	CSgPtr<CSgTranslate> move = new CSgTranslate();
	move->SetProperties(0.0,0.0,-1*m_SeatDepth*.1);
	CreateSeatContainerBottom(parent);
	CreateSeatContainerBack(parent);

}

void CScrambledEggsFactory::CreateSeatContainerBottom(CSgComposite *parent)
{
	/*******************************************************************/
	/************************Bottom of cart*****************************/
	/*******************************************************************/
	CSgPtr<CSgMesh> bottomSideLeft = new CSgMesh();
	CSgPtr<CSgMesh> bottomSideRight = new CSgMesh();
	CSgPtr<CSgMesh> frontLeft = new CSgMesh();
	CSgPtr<CSgMesh> frontRight = new CSgMesh();
	CSgPtr<CSgMesh> leftTop = new CSgMesh();
	CSgPtr<CSgMesh> rightTop = new CSgMesh();

	double minX = (1.0/pow(m_SeatHeight,(1.0/9.0)));
	double maxSeatWidth = m_SeatWidth+2.0*minX;
	std::vector< CGrVector > bottomPointsLeft;
	std::vector< CGrVector > topPointsLeft;
	std::vector< CGrVector > bottomPointsRight;
	std::vector< CGrVector > topPointsRight;

	

	for(double i = minX; i <= ((m_SeatWidth/2.0)+minX) ; i+=((m_SeatWidth/2.0)/(m_SeatSides/2.0)) )
	{
		double x = i;
		double y =  1.0/pow(x,9.0);
		double yInv = 9.0*pow(x,10.0);

		bottomSideLeft->AddVertex( CGrVector(x, y , 0.0));
		bottomSideLeft->AddVertex( CGrVector(x, y , m_SeatDepth));
		bottomPointsLeft.push_back(CGrVector(x, y , m_SeatDepth));
		GLdouble n[] = {-1.0*x, -1.0*yInv, 0.0};
		Normalize(n);
		bottomSideLeft->AddNormal(CGrVector(n));

		bottomSideRight->AddVertex( CGrVector(maxSeatWidth-x, y , 0.0));
		bottomSideRight->AddVertex( CGrVector(maxSeatWidth-x, y , m_SeatDepth));
		bottomPointsRight.push_back(CGrVector(maxSeatWidth-x, y , m_SeatDepth));

		n[0] = x;
		Normalize(n);
		bottomSideRight->AddNormal(CGrVector(n));
		if(i == minX)
		{
			leftTop->AddVertex(CGrVector(x, y , 0.0));
			leftTop->AddVertex( CGrVector(x, y , m_SeatDepth));
			rightTop->AddVertex( CGrVector(maxSeatWidth-x, y , 0.0));
			rightTop->AddVertex( CGrVector(maxSeatWidth-x, y , m_SeatDepth));
		}
	}
	for ( unsigned int i = 0; i < (m_SeatSides-1); i+=2 )
	{
		bottomSideLeft->AddFlatQuad(i+3, i+1, i, i+2, i/2);
		bottomSideRight->AddFlatQuad(i+2, i, i+1, i+3, i/2);
	}

	parent->AddChild(bottomSideLeft);
	parent->AddChild(bottomSideRight);
	/*******************************************************************/
	/*******************************************************************/

	/*******************************************************************/
	/************************Top of cart********************************/
	/*******************************************************************/
	CSgPtr<CSgMesh> topSideLeft = new CSgMesh();
	CSgPtr<CSgMesh> topSideRight = new CSgMesh();

	double minX2 = (1.0/pow((m_SeatHeight*.8),(1.0/7.0)));
	double minSeatWidth = m_SeatWidth*.8;
	double maxSeatWidth2 = minSeatWidth+2.0*minX2;

	for(double i = minX2; i <= ((minSeatWidth/2.0)+minX2)+((minSeatWidth/2.0)/(m_SeatSides/2.0)) ; i+=((minSeatWidth/2.0)/(m_SeatSides/2.0)) )
	{
		double x = i;
		double y =  1.0/pow(x,7.0);
		double yInv = 7.0*pow(x,8.0);

		topSideLeft->AddVertex( CGrVector(x+m_SeatWidth*.1, y+m_SeatHeight*.2 , 0.0));
		topSideLeft->AddVertex( CGrVector(x+m_SeatWidth*.1, y+m_SeatHeight*.2 , m_SeatDepth));
		topPointsLeft.push_back(CGrVector((x+m_SeatWidth*.1), y+m_SeatHeight*.2 , m_SeatDepth));
		GLdouble n[] = {x,yInv, 0.0};
		Normalize(n);
		topSideLeft->AddNormal(CGrVector(n));

		topSideRight->AddVertex( CGrVector(maxSeatWidth2-x+m_SeatWidth*.1, y+m_SeatHeight*.2, 0.0));
		topSideRight->AddVertex( CGrVector(maxSeatWidth2-x+m_SeatWidth*.1, y+m_SeatHeight*.2 , m_SeatDepth));
		topPointsRight.push_back(CGrVector(maxSeatWidth2-x+m_SeatWidth*.1, y+m_SeatHeight*.2 , m_SeatDepth));
		n[0] = -1*x;
		Normalize(n);
		topSideRight->AddNormal(CGrVector(n));

		if(i == minX2)
		{
			leftTop->AddVertex(CGrVector(x+m_SeatWidth*.1, y+m_SeatHeight*.2 , 0.0));
			leftTop->AddVertex( CGrVector(x+m_SeatWidth*.1, y+m_SeatHeight*.2 , m_SeatDepth));
			rightTop->AddVertex( CGrVector(maxSeatWidth2-x+m_SeatWidth*.1, y+m_SeatHeight*.2, 0.0));
			rightTop->AddVertex( CGrVector(maxSeatWidth2-x+m_SeatWidth*.1, y+m_SeatHeight*.2 , m_SeatDepth));
		}
	}
	//add the verticies in the correct order to the front
	for(unsigned int i = 0; i < (m_SeatSides/2)+1;i++)
	{
		frontLeft->AddVertex(bottomPointsLeft[i]);
		frontLeft->AddVertex(topPointsLeft[i]);
		frontRight->AddVertex(topPointsRight[i]);
		frontRight->AddVertex(bottomPointsRight[i]);
	}
	frontRight->AddNormal(CGrVector(0.0,0.0,1.0));
	frontLeft->AddNormal(CGrVector(0.0,0.0,1.0));

	for ( unsigned int i = 0; i < (m_SeatSides); i+=2 )
	{
		topSideLeft->AddFlatQuad(i, i+1, i+3, i+2, i/2);
		topSideRight->AddFlatQuad(i+3, i+1, i, i+2, i/2);

		frontLeft->AddFlatQuad(i+1,i,i+2,i+3,0);
		frontRight->AddFlatQuad(i+1,i,i+2,i+3,0);
	}

	parent->AddChild(topSideLeft);
	parent->AddChild(topSideRight);

	parent->AddChild(frontLeft);
	parent->AddChild(frontRight);

	leftTop->AddNormal(CGrVector(0.0,1.0,0.0));
	leftTop->AddFlatQuad(2,0,1,3,0);
	rightTop->AddNormal(CGrVector(0.0,1.0,0.0));
	rightTop->AddFlatQuad(0,2,3,1,0);

	parent->AddChild(rightTop);
	parent->AddChild(leftTop);

}

void CScrambledEggsFactory::CreateSeatContainerBack(CSgComposite *parent)
{
	/*******************************************************************/
	/************************Bottom of cart*****************************/
	/*******************************************************************/
	CSgPtr<CSgMesh> bottomSideLeft = new CSgMesh();
	CSgPtr<CSgMesh> bottomSideRight = new CSgMesh();
	CSgPtr<CSgMesh> frontLeft = new CSgMesh();
	CSgPtr<CSgMesh> frontRight = new CSgMesh();

	double minX = (1.0/pow(m_SeatHeight,(1.0/9.0)));
	double maxSeatWidth = m_SeatWidth+2.0*minX;

	std::vector< CGrVector > frontLeftPoints;
	std::vector< CGrVector > frontRightPoints;
	std::vector< CGrVector > backLeftPoints;
	std::vector< CGrVector > backRightPoints;
	std::vector< CGrVector > backLeftTex;
	std::vector< CGrVector > backRightTex;
	

	for(double i = minX; i <= ((m_SeatWidth/2.0)+minX) ; i+=((m_SeatWidth/2.0)/(m_SeatSides/2.0)) )
	{
		double counter = ((i-minX)/((m_SeatWidth/2.0)/(m_SeatSides/2.0)));
		double x = i;
		double y =  1.0/pow(x,9.0);
		double yInv = 9.0*pow(x,10.0);

		bottomSideLeft->AddVertex( CGrVector(x, y , 0.0));
		bottomSideLeft->AddVertex( CGrVector(x, y , m_SeatDepth*.1));
		backLeftPoints.push_back(CGrVector(x, y , 0.0));
		if(counter < 30)
		{
			backLeftTex.push_back(CGrVector(0.0,1.0-counter/(m_SeatSides/4.0)));
		}
		else
		{
			backLeftTex.push_back(CGrVector(counter/(m_SeatSides/2.0)-.5,0.0));
		}
		frontLeftPoints.push_back(CGrVector(x, y , m_SeatDepth*.1));
		GLdouble n[] = {-1.0*x, -1.0*yInv, 0.0};
		Normalize(n);
		bottomSideLeft->AddNormal(CGrVector(n));

		bottomSideRight->AddVertex( CGrVector(maxSeatWidth-x, y , 0.0));
		bottomSideRight->AddVertex( CGrVector(maxSeatWidth-x, y , m_SeatDepth*.1));
		backRightPoints.push_back(CGrVector(maxSeatWidth-x, y , 0.0));
		if(counter < 30)
		{
			backRightTex.push_back(CGrVector(1.0,1.0-counter/(m_SeatSides/4.0)));
		}
		else
		{
			backRightTex.push_back(CGrVector((60-counter)/(m_SeatSides/2.0)+.5,0.0));
		}
		frontRightPoints.push_back(CGrVector(maxSeatWidth-x, y , m_SeatDepth*.1));

		n[0] = x;
		Normalize(n);
		bottomSideRight->AddNormal(CGrVector(n));
	}
	for ( unsigned int i = 0; i < (m_SeatSides-1); i+=2 )
	{
		bottomSideLeft->AddFlatQuad(i+3, i+1, i, i+2, i/2);
		bottomSideRight->AddFlatQuad(i+2, i, i+1, i+3, i/2);
	}

	parent->AddChild(bottomSideLeft);
	parent->AddChild(bottomSideRight);

	CSgPtr<CSgMesh> backPanel = new CSgMesh();
	CSgPtr<CSgMesh> frontPanel = new CSgMesh();
	backPanel->AddVertex(CGrVector((m_SeatWidth/2.0)+minX, m_SeatHeight,0.0) );
	backPanel->AddTexCoord(CGrVector(.5,1.0));
	frontPanel->AddVertex(CGrVector((m_SeatWidth/2.0)+minX, m_SeatHeight,m_SeatDepth*.1) );
	backPanel->AddNormal(CGrVector(0.0,0.0,-1.0));
	frontPanel->AddNormal(CGrVector(0.0,0.0,1.0));

	for(int i = 0; i < ((m_SeatSides/2.0)+1); i++)
	{
		backPanel->AddVertex(backLeftPoints[i]);
		backPanel->AddTexCoord(backLeftTex[i]);
		frontPanel->AddVertex(frontLeftPoints[i]);
	}
	for(int i = 0; i < ((m_SeatSides/2.0)+1); i++)
	{
		backPanel->AddVertex(backRightPoints[i]);
		backPanel->AddTexCoord(backRightTex[i]);
		frontPanel->AddVertex(frontRightPoints[i]);
	}
	for(int i = 1; i < m_SeatSides/2+1;i++)
	{
		backPanel->AddFlatTriangle(0,i+1,i,0,1);
		backPanel->AddFlatTriangle(0,i+61,i+62,0,1);
		frontPanel->AddFlatTriangle(0,i,i+1,0);
		frontPanel->AddFlatTriangle(0,i+62,i+61,0);
	}

	backOfChair->AddChild(backPanel);
	backOfChair->AddChild(frontPanel);

	parent->AddChild(backOfChair);
	//parent->AddChild(frontPanel);

	//top piece
	CSgPtr<CSgMesh> backTop = new CSgMesh();
	backTop->AddVertex(backLeftPoints[0]);
	backTop->AddVertex(frontLeftPoints[0]);
	backTop->AddVertex(backRightPoints[0]);
	backTop->AddVertex(frontRightPoints[0]);
	backTop->AddNormal(CGrVector(0.0,1.0,0.0));
	backTop->AddFlatQuad(0,1,3,2,0);
	parent->AddChild(backTop);
}

void CScrambledEggsFactory::CreateCartStair(CSgComposite *parent)
{


	CSgPtr<CSgComposite> stairComposite = new CSgComposite();
	CSgPtr<CSgPolygon> leftOutside = new CSgPolygon();
	CSgPtr<CSgPolygon> rightOutside = new CSgPolygon();
	CSgPtr<CSgPolygon> leftInside = new CSgPolygon();
	CSgPtr<CSgPolygon> rightInside = new CSgPolygon();

	//  dc
	// / |
	//a--b
	//m_FrontSides
	GLdouble a3[] = {0.0,0.0,0.0};
	GLdouble b3[] = {m_StairDepth,0.0,0.0};
	GLdouble c3[] = {m_StairDepth,m_FrontRadius,0.0};
	GLdouble d3[] = {m_StairDepth*.7,m_FrontRadius,0.0};

	rightOutside->AddVertices(a3,b3,c3,d3);
	rightInside->AddVertices(d3,c3,b3,a3);
	stairComposite->AddChild(rightOutside);
	stairComposite->AddChild(rightInside);

	leftOutside->AddVertices(a3,b3,c3,d3);
	leftInside->AddVertices(d3,c3,b3,a3);

	CSgPtr<CSgTranslate> leftMove = new CSgTranslate();
	leftMove->SetProperties(0.0,0.0,-m_StairWidth);
	leftMove->AddChild(leftOutside);
	leftMove->AddChild(leftInside);
	stairComposite->AddChild(leftMove);

	//part you step on
	GLdouble a1[] = {0.0,0.0,0.0};
	GLdouble b1[] = {m_StairDepth,0.0,0.0};
	GLdouble c1[] = {m_StairDepth,m_FrontRadius,-1.0*m_StairWidth};
	GLdouble d1[] = {0.0,0.0,-1.0*m_StairWidth};
	

	CSgPtr<CSgPolygon> bottomTop = new CSgPolygon();
	CSgPtr<CSgPolygon> bottomBottom = new CSgPolygon();

	bottomTop->AddVertices(a1,b1,c1,d1);
	bottomBottom->AddVertices(d1,c1,b1,a1);
	stairComposite->AddChild(bottomTop);
	stairComposite->AddChild(bottomBottom);

	//back of stairs
	GLdouble a2[] = {m_StairDepth,0.0,-1.0*m_StairWidth};
	GLdouble b2[] = {m_StairDepth,0.0,0.0};
	GLdouble c2[] = {m_StairDepth,m_FrontRadius,0.0};
	GLdouble d2[] = {m_StairDepth,m_FrontRadius,-1.0*m_StairWidth};

	CSgPtr<CSgPolygon> backFront= new CSgPolygon();
	CSgPtr<CSgPolygon> backBack = new CSgPolygon();

	backFront->AddVertices(a2,b2,c2,d2);
	backBack->AddVertices(d2,c2,b2,a2);

	stairComposite->AddChild(backFront);
	stairComposite->AddChild(backBack);


	CSgPtr<CSgRotateAroundPoint> stairRotation = new CSgRotateAroundPoint();
	stairRotation->SetPoint(0.0,0.0,0.0);
	stairRotation->SetAngle(90);
	stairRotation->SetNormal(0.0,0.0,-1.0);
	stairRotation->AddChild(stairComposite);

	CSgPtr<CSgTranslate> stairMove = new CSgTranslate();
	stairMove->SetProperties(-1.0*m_FrontRadius,4.0+m_StairDepth,0.0);
	stairMove->AddChild(stairRotation);

	parent->AddChild(stairMove);
}



void CScrambledEggsFactory::CreateCartFront(CSgComposite *parent)
{

	CSgPtr<CSgComposite> roundedFront = new CSgComposite();
	for(double i = 0;i < m_FrontSides; i++)
	{
		//a  c
		//b  d
		std::vector< std::vector<GLfloat> > texCoords(4);
		GLdouble a[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[0].push_back(0.0);
		texCoords[0].push_back(GLfloat(((a[0]/m_FrontRadius)+1)/2.0));
		GLdouble b[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[1].push_back(0.0);
		texCoords[1].push_back(GLfloat(((b[0]/m_FrontRadius)+1)/2.0));
		GLdouble c[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),m_FrontWidth,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[2].push_back(1.0);
		texCoords[2].push_back(GLfloat(((c[0]/m_FrontRadius)+1)/2.0));
		GLdouble d[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),m_FrontWidth,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[3].push_back(1.0);
		texCoords[3].push_back(GLfloat(((d[0]/m_FrontRadius)+1)/2.0));
		CSgPtr<CSgQuad> newQuad = new CSgQuad();
		newQuad->SetProperties(a,b,c,d);
		newQuad->SetTex(texCoords);
		// Normalized avg between top 2 (or bottom 2) coordinates, no y coordinate)
		GLdouble normal[] = {(d[0] + c[0]) / 2.0, 0, (d[2] + c[2]) / 2.0};
		Normalize(normal);
		newQuad->SetNormal(normal);
		roundedFront->AddChild(newQuad);
	}

	CSgPtr<CSgPolygon> leftSide = new CSgPolygon();
	CSgPtr<CSgPolygon> rightSide = new CSgPolygon(); 
	for (double i = 0; i < m_FrontSides; i++)
	{
		GLdouble start[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		GLdouble end[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		rightSide->AddVertex3dv(start);
		rightSide->AddVertex3dv(end);
		leftSide->AddVertex3dv(start);
		leftSide->AddVertex3dv(end);
	}
	roundedFront->AddChild(rightSide);

	CSgPtr<CSgRotateAroundPoint> leftRotation = new CSgRotateAroundPoint();
	leftRotation->SetPoint(0.0,0.0,0.0);
	leftRotation->SetAngle(180);
	leftRotation->SetNormal(0.0,0.0,1.0);
	leftRotation->AddChild(leftSide);

	CSgPtr<CSgTranslate> leftMove = new CSgTranslate();
	leftMove->SetProperties(0.0,m_FrontWidth,0.0);
	leftMove->AddChild(leftRotation);

	roundedFront->AddChild(leftMove);

	roundedFrontTex->AddChild(roundedFront);
	parent->AddChild(roundedFrontTex);

	//inside view
	CSgPtr<CSgComposite> roundedBack = new CSgComposite();
	for(double i = 0;i < m_FrontSides; i++)
	{
		std::vector< std::vector<GLfloat> > texCoords(4);
		GLdouble a[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[0].push_back(1.0);
		texCoords[0].push_back(GLfloat(a[2]/m_FrontRadius));
		GLdouble b[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[1].push_back(1.0);
		texCoords[1].push_back(GLfloat(b[2]/m_FrontRadius));
		GLdouble c[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),m_FrontWidth,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[2].push_back(0.0);
		texCoords[2].push_back(GLfloat(c[2]/m_FrontRadius));
		GLdouble d[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),m_FrontWidth,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		texCoords[3].push_back(0.0);
		texCoords[3].push_back(GLfloat(d[2]/m_FrontRadius));
		CSgPtr<CSgQuad> newQuad = new CSgQuad();
		newQuad->SetProperties(d,c,b,a);
		newQuad->SetTex(texCoords);
		// Normalized avg between top 2 (or bottom 2) coordinates, no y coordinate)
		GLdouble normal[] = {-1*((d[0] + c[0]) / 2.0), 0, -1*((d[2] + c[2]) / 2.0)};
		Normalize(normal);
		newQuad->SetNormal(normal);
		roundedBack->AddChild(newQuad);
	}

	CSgPtr<CSgPolygon> leftInside = new CSgPolygon();
	CSgPtr<CSgPolygon> rightInside = new CSgPolygon(); 
	for (double i = 0; i < m_FrontSides; i++)
	{
		GLdouble start[] = {m_FrontRadius*cos(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin(i*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		GLdouble end[] = {m_FrontRadius*cos((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0)),0.0,m_FrontRadius*sin((i+1)*M_PI/m_FrontSides+M_PI/(m_FrontSides*2.0))};
		rightInside->AddVertex3dv(start);
		rightInside->AddVertex3dv(end);
		leftInside->AddVertex3dv(start);
		leftInside->AddVertex3dv(end);
	}

	CSgPtr<CSgRotateAroundPoint> rightInsideRotation = new CSgRotateAroundPoint();
	rightInsideRotation->SetPoint(0.0,0.0,0.0);
	rightInsideRotation->SetAngle(180);
	rightInsideRotation->SetNormal(0.0,0.0,1.0);
	rightInsideRotation->AddChild(rightInside);

	roundedBack->AddChild(rightInsideRotation);

	CSgPtr<CSgTranslate> leftInsideMove = new CSgTranslate();
	leftInsideMove->SetProperties(0.0,m_FrontWidth,0.0);
	leftInsideMove->AddChild(leftInside);
	roundedBack->AddChild(leftInsideMove);

	parent->AddChild(roundedBack);

	
}